package com.hiwan.wechat.quartz;

import java.util.Date;

import org.apache.log4j.Logger;
import org.quartz.SchedulerException;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.hiwan.wechat.enumeration.CorpAppInfoEnum;
import com.hiwan.wechat.service.WechatService;

/**
 * 每隔1小时获取一次AccessToken
 */
@Service
public class JsApiTicketQuartz {

	Logger logger = Logger.getLogger(JsApiTicketQuartz.class);
	
	/**
	 * 每隔2小时更新
	 * @throws SchedulerException
	 */
	@Scheduled(cron="0 0 0/2 * * ?") //需要注意@Scheduled这个注解，它可配置多个属性：cron\fixedDelay\fixedRate
    public void checkUpdate() throws SchedulerException {
		logger.info("start check JsApiTicket" + new Date());

		CorpAppInfoEnum[] s = CorpAppInfoEnum.values();
        for (CorpAppInfoEnum e : s) {
        	WechatService.updateJsApiTicket(e);
        }
		
		logger.info("end check JsApiTicket" + new Date());
	}
	
}
